package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressReconciliationYzInstall;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressReconciliationYzInstallMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationYzInstallParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressReconciliationYzInstallResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressReconciliationYzInstallService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 邮政报价设置 服务实现类
 * </p>
 *
 * @author 
 * @since 2022-12-26
 */
@Service
public class ToolExpressReconciliationYzInstallServiceImpl extends ServiceImpl<ToolExpressReconciliationYzInstallMapper, ToolExpressReconciliationYzInstall> implements ToolExpressReconciliationYzInstallService {

    @Override
    public void add(ToolExpressReconciliationYzInstallParam param){
        ToolExpressReconciliationYzInstall entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressReconciliationYzInstallParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressReconciliationYzInstallParam param){
        ToolExpressReconciliationYzInstall oldEntity = getOldEntity(param);
        ToolExpressReconciliationYzInstall newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressReconciliationYzInstallResult findBySpec(ToolExpressReconciliationYzInstallParam param){
        return null;
    }

    @Override
    public List<ToolExpressReconciliationYzInstallResult> findListBySpec(ToolExpressReconciliationYzInstallParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressReconciliationYzInstallParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressReconciliationYzInstallParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressReconciliationYzInstall getOldEntity(ToolExpressReconciliationYzInstallParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressReconciliationYzInstall getEntity(ToolExpressReconciliationYzInstallParam param) {
        ToolExpressReconciliationYzInstall entity = new ToolExpressReconciliationYzInstall();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
